package com.job.sun.HomeWork0719;

import java.time.chrono.IsoChronology;
import java.util.*;
import java.util.concurrent.CountDownLatch;

/**
 * @author 张春阳
 * @version 1.0
 * @since 2022-07-19 17:53:30
 */
public class HomeWork {
    public static void main(String[] args) {
        Random ran = new Random();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入排序个数");
        int anInt = sc.nextInt();
        List<Integer> integers = new ArrayList<>();
        //填充集合
        while (integers.size() < anInt) {
            integers.add(ran.nextInt(100) + 1);
        }

        Stack<Integer> s = new Stack<>();
      //  s.push(null);
        Stack<Integer> s2 = new Stack<>();
     //   s2.push(null);
        for (int i = 0; i < integers.size(); i++) {
            int count = 0;
            //到将集合中的数值输入的栈中停止
            while (count == 0) {
                if (s.empty() || s.peek() <= integers.get(i)) {
                    s.push(integers.get(i));
                    count++;
                } else {
                    s2.push(s.pop());
                }
            }
         //   将s2中的数输入到s中之后停止
            while (!s2.empty()) {
                s.push(s2.pop());
            }
        }
        integers.clear();
        for (int i = 0; i < anInt; i++) {
            integers.add(s.pop());
        }

        for (int i = 0; i < anInt; i++) {
            System.out.println(integers.get(i));
        }


    }


}